const baseURL = 'http://localhost:3000/api/'
const request = ({
    url,
    method = 'GET',
    header = {},
    data,
    tip = '数据加载中'
}) => {
    return new Promise((resolve, reject) => {
        // 发送请求前显示提示
        uni.showLoading({
            title: tip,
            icon: 'none'
        });
        const token = uni.getStorageSync('token')
        if (token) {
            header.Authorization = token
        }
        uni.request({
            url: `${baseURL}${url}`, //仅为示例，并非真实接口地址。
            method,
            header,
            data,
            success: (res) => {
                resolve(res)
            },
            fail: (err) => {
                reject(res)
            },
            complete: () => {
                uni.hideLoading();
            }
        });
    })
}

export default request